package com.example.administrator.himalaya.testPackage;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.activity.EnerMasterActivity;
import com.example.administrator.himalaya.entity.recommendentity.EditRecommendList;
import com.example.administrator.himalaya.entity.recommendentity.GuessList;
import com.example.administrator.himalaya.entity.recommendentity.HotRecommendsList;
import com.example.administrator.himalaya.entity.recommendentity.HotRecommendsListList;
import com.example.administrator.himalaya.entity.recommendentity.RecommendEditorRecommend;
import com.example.administrator.himalaya.entity.recommendentity.RecommendEntity;
import com.example.administrator.himalaya.entity.recommendentity.RecommendEntity02Guss;
import com.example.administrator.himalaya.entity.recommendentity.RecommendEntityInterFace02;
import com.example.administrator.himalaya.entity.recommendentity.RecommendSpecial;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liuchao on 2016/12/2.
 */

public class MytestAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<RecommendEntity> list;
    private Context context;
    private List<RecommendEntityInterFace02> list2;

    public MytestAdapter(List<RecommendEntity> list,List<RecommendEntityInterFace02> list2, Context context) {
        this.list = list;
        this.context = context;
        this.list2=list2;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return R.layout.recommend_item_guess;
        }else if(position ==2) {
            return R.layout.recommend_item_highquality;
        }
        else if(position==3){
            return R.layout.recommend_item_generalize;
        }
        else if(position==1){
            return R.layout.recommend_item_editorrecommendalbums;
        }
        else {
            return R.layout.recommend_item_hotrecommends;
        }

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(viewType, parent, false);

        if (viewType == R.layout.recommend_item_editorrecommendalbums) {
            IFOneViewHolder holder = new IFOneViewHolder(view);
            return holder;
        } else if (viewType == R.layout.recommend_item_guess) {
            IFTwoViewHolder holder = new IFTwoViewHolder(view);
            return holder;
        }else if(viewType == R.layout.recommend_item_highquality){
            HighQualityViewHolder holder=new HighQualityViewHolder(view);
            return holder;
        }else if(viewType == R.layout.recommend_item_generalize){
            GeneralizeViewHolder holder=new GeneralizeViewHolder(view);
            return holder;
        }else if(viewType == R.layout.recommend_item_hotrecommends){

            IFOneViewHolder holder = new IFOneViewHolder(view);
            return holder;
        }

        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //editorRecommendAlbums
        int testdata;
        if (position == 0&&list2.size()!=0) {
            final IFTwoViewHolder holderTwo = (IFTwoViewHolder) holder;
            RecommendEntity02Guss guess = list2.get(position).getGuess();
            String title = guess.getTitle();
            holderTwo.textViewTitle.setText(title);
            List<GuessList> guessList = guess.getList();
            int listCount = guessList.size();
            for (int i = 0; i < 6; i++) {
                holderTwo.textViewlistId.get(i).setText(guessList.get(i).getId()+"");
                  final int id=guessList.get(i).getId();
                holderTwo.textViewlist.get(i).setText(guessList.get(i).getTitle());
                PicLoad.loadImage(holderTwo.imageViewList.get(i),guessList.get(i).getCoverSmall());
                holderTwo.imageViewList.get(i).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context, "猜你喜欢"+id, Toast.LENGTH_SHORT).show();
                        Intent intent =new Intent(context, EnerMasterActivity.class);
                        intent.putExtra("id",id+"");
                        context.startActivity(intent);

                    }
                });
            }
        } else if (position == 2&&list.size()!=0) {
            HighQualityViewHolder highQualityViewHolder=(HighQualityViewHolder)holder;
            RecommendSpecial specialColumn = list.get(0).getSpecialColumn();
            highQualityViewHolder.textViewTitle.setText(specialColumn.getTitle());
            highQualityViewHolder.textView01.setText(specialColumn.getList().get(0).getTitle());
            PicLoad.loadImage(highQualityViewHolder.imageView01,specialColumn.getList().get(0).getCoverPath());
            highQualityViewHolder.imageView01.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "精品单听", Toast.LENGTH_SHORT).show();
                }
            });
        } else if (position == 3) {
//            GeneralizeViewHolder generalizeViewHolder=(GeneralizeViewHolder)holder;
//            generalizeViewHolder

        } else if(position==1&&list.size()!=0) {
            IFOneViewHolder holderone = (IFOneViewHolder) holder;
            RecommendEditorRecommend editorRecommendAlbums = list.get(0).getEditorRecommendAlbums();
            String title = editorRecommendAlbums.getTitle();
            holderone.textViewTitle.setText(title);
            List<EditRecommendList> editRecommendLists = editorRecommendAlbums.getList();
            int listCount = editRecommendLists.size();
            holderone.textView01.setText(editRecommendLists.get(0).getTrackTitle());
            PicLoad.loadImage(holderone.imageView01, editRecommendLists.get(0).getCoverSmall());
            holderone.imageView01.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "小编推荐", Toast.LENGTH_SHORT).show();
                }
            });
            holderone.textView02.setText(editRecommendLists.get(1).getTrackTitle());
            PicLoad.loadImage(holderone.imageView02, editRecommendLists.get(1).getCoverSmall());
            holderone.imageView02.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "小编推荐", Toast.LENGTH_SHORT).show();
                }
            });
            holderone.textView03.setText(editRecommendLists.get(2).getTrackTitle());
            PicLoad.loadImage(holderone.imageView03, editRecommendLists.get(2).getCoverSmall());
            holderone.imageView03.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "小编推荐", Toast.LENGTH_SHORT).show();
                }
            });
        }
        else if(list2.size()!=0&&position!=1&&position!=2&&position!=3&&position!=0){
            IFOneViewHolder holderone = (IFOneViewHolder) holder;
            List<HotRecommendsList> hotRecommendsLists = list2.get(0).getHotRecommends().getList();

            HotRecommendsList hotRecommendsList1 = hotRecommendsLists.get(position - 4);
            holderone.textViewTitle.setText(hotRecommendsList1.getTitle());
            List<HotRecommendsListList> list = hotRecommendsList1.getList();
//            int listCount = list.size();
//            holderone.textView01.setText(list.get(0).getTitle());
//            PicLoad.loadImage(holderone.imageView01, list.get(0).getCoverSmall());
//            holderone.textView02.setText(list.get(1).getTrackTitle());
//            PicLoad.loadImage(holderone.imageView02, list.get(1).getCoverSmall());
//            holderone.textView03.setText(list.get(2).getTrackTitle());
//            PicLoad.loadImage(holderone.imageView03, list.get(2).getCoverSmall());

            for (int i = 0; i < 3; i++) {
                holderone.listtexttitle.get(i).setText(list.get(i).getTitle());
                holderone.imageViewList.get(i).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(context,"Hot推荐",Toast.LENGTH_SHORT).show();
                    }
                });
                PicLoad.loadImage(holderone.imageViewList.get(i),list.get(i).getAlbumCoverUrl290());
                holderone.listtexttrackTitle.get(i).setText(list.get(i).getTrackTitle());
            }
        }

    }

    public void adddatas(RecommendEntity collection,RecommendEntityInterFace02 collection02) {
      if(collection!=null)  list.add(collection);
        if(collection02!=null)list2.add(collection02);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {

        return list2.size()==0?4 : 4+list2.get(0).getHotRecommends().getList().size();
    }


    public static class IFOneViewHolder extends RecyclerView.ViewHolder {
        private TextView textViewTitle, textView01, textView02, textView03;
        private ImageView imageView01, imageView02, imageView03;
        private TextView textViewtrackTitle01, textViewtrackTitle02, textViewtrackTitle03;
        private List<TextView> listtexttitle,listtexttrackTitle;
        private List<ImageView> imageViewList;
        public IFOneViewHolder(View itemView) {
            super(itemView);
            listtexttitle = new ArrayList<>();
            listtexttrackTitle = new ArrayList<>();
            imageViewList = new ArrayList<>();
            textViewTitle = (TextView) itemView.findViewById(R.id.layout00).findViewById(R.id.find_title);
            textView01 = (TextView) itemView.findViewById(R.id.layout01).findViewById(R.id.theme_title);
            imageView01 = (ImageView) itemView.findViewById(R.id.layout01).findViewById(R.id.theme_pic);
            textView02 = (TextView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_title);
            imageView02 = (ImageView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_pic);
            textView03 = (TextView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_title);
            imageView03 = (ImageView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_pic);
            textViewtrackTitle01 = (TextView) itemView.findViewById(R.id.layout01).findViewById(R.id.theme_trackTitle);
            textViewtrackTitle02 = (TextView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_trackTitle);
            textViewtrackTitle03 = (TextView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_trackTitle);
            listtexttitle.add(textView01);
            listtexttitle.add(textView02);
            listtexttitle.add(textView03);
            imageViewList.add(imageView01);
            imageViewList.add(imageView02);
            imageViewList.add(imageView03);
            listtexttrackTitle.add(textViewtrackTitle01);
            listtexttrackTitle.add(textViewtrackTitle02);
            listtexttrackTitle.add(textViewtrackTitle03);

        }
    }

    public static class IFTwoViewHolder extends RecyclerView.ViewHolder {
        private TextView textViewTitle, textView01, textView02, textView03;
        private TextView textView04, textView05, textView06;
        private ImageView imageView01, imageView02, imageView03;
        private ImageView imageView04, imageView05, imageView06;
        private TextView TextViewId01, TextViewId02, TextViewId03;
        private TextView TextViewId04, TextViewId05, TextViewId06;
        List<TextView> textViewlist;
        List<ImageView> imageViewList;
        List<TextView> textViewlistId;
        public IFTwoViewHolder(View itemView) {
            super(itemView);
            textViewlist = new ArrayList<>();
            imageViewList = new ArrayList<>();
            textViewlistId=new ArrayList<>();
            textViewTitle = (TextView) itemView.findViewById(R.id.layout00).findViewById(R.id.find_title);
            textView01 = (TextView) itemView.findViewById(R.id.layout01).findViewById(R.id.theme_title);
            imageView01 = (ImageView) itemView.findViewById(R.id.layout01).findViewById(R.id.theme_pic);
            textView02 = (TextView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_title);
            imageView02 = (ImageView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_pic);
            textView03 = (TextView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_title);
            imageView03 = (ImageView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_pic);
            textView04 = (TextView) itemView.findViewById(R.id.layout04).findViewById(R.id.theme_title);
            imageView04 = (ImageView) itemView.findViewById(R.id.layout04).findViewById(R.id.theme_pic);
            textView05 = (TextView) itemView.findViewById(R.id.layout05).findViewById(R.id.theme_title);
            imageView05 = (ImageView) itemView.findViewById(R.id.layout05).findViewById(R.id.theme_pic);
            textView06 = (TextView) itemView.findViewById(R.id.layout06).findViewById(R.id.theme_title);
            imageView06 = (ImageView) itemView.findViewById(R.id.layout06).findViewById(R.id.theme_pic);
            textViewlist.add(textView01);
            textViewlist.add(textView02);
            textViewlist.add(textView03);
            textViewlist.add(textView04);
            textViewlist.add(textView05);
            textViewlist.add(textView06);
            imageViewList.add(imageView01);
            imageViewList.add(imageView02);
            imageViewList.add(imageView03);
            imageViewList.add(imageView04);
            imageViewList.add(imageView05);
            imageViewList.add(imageView06);
            TextViewId01 = (TextView) itemView.findViewById(R.id.layout01).findViewById(R.id.theme_id);
            TextViewId02 = (TextView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_id);
            TextViewId03 = (TextView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_id);
            TextViewId04 = (TextView) itemView.findViewById(R.id.layout04).findViewById(R.id.theme_id);
            TextViewId05 = (TextView) itemView.findViewById(R.id.layout05).findViewById(R.id.theme_id);
            TextViewId06 = (TextView) itemView.findViewById(R.id.layout06).findViewById(R.id.theme_id);
            textViewlistId.add(TextViewId01);
            textViewlistId.add(TextViewId02);
            textViewlistId.add(TextViewId03);
            textViewlistId.add(TextViewId04);
            textViewlistId.add(TextViewId05);
            textViewlistId.add(TextViewId06);

        }
    }
    public static class HighQualityViewHolder extends RecyclerView.ViewHolder {
        private TextView textViewTitle, textView01, textView02, textView03;
        private ImageView imageView01, imageView02, imageView03;

        public HighQualityViewHolder(View itemView) {
            super(itemView);
            textViewTitle = (TextView) itemView.findViewById(R.id.layout00).findViewById(R.id.find_title);
            textView01 = (TextView) itemView.findViewById(R.id.heghquality_title);
            imageView01 = (ImageView) itemView.findViewById(R.id.heghquality_pic);
//            textView02 = (TextView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_title);
//            imageView02 = (ImageView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_pic);
//            textView03 = (TextView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_title);
//            imageView03 = (ImageView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_pic);

        }
    }
    public static class GeneralizeViewHolder extends RecyclerView.ViewHolder {
        private TextView textViewTitle, textView01, textView02, textView03;
        private ImageView imageView01, imageView02, imageView03;

        public GeneralizeViewHolder(View itemView) {
            super(itemView);
            textViewTitle = (TextView) itemView.findViewById(R.id.layout00).findViewById(R.id.find_title);
            textView01 = (TextView) itemView.findViewById(R.id.generalize_title);
            imageView01 = (ImageView) itemView.findViewById(R.id.generalize_pic);
//            textView02 = (TextView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_title);
//            imageView02 = (ImageView) itemView.findViewById(R.id.layout02).findViewById(R.id.theme_pic);
//            textView03 = (TextView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_title);
//            imageView03 = (ImageView) itemView.findViewById(R.id.layout03).findViewById(R.id.theme_pic);

        }
    }
}
